package cn.com.cfae.iras.doc.analyze.components.commonsense;

import cn.com.cfae.iras.doc.analyze.components.BaseComponent;
import cn.com.cfae.iras.doc.analyze.components.beans.ComponentResult;
import cn.com.cfae.iras.doc.analyze.components.consistency.U1004;
import cn.com.cfae.iras.doc.analyze.parse.kv.KVText;
import cn.com.cfae.iras.doc.analyze.parse.kv.TextLayout;
import cn.com.cfae.iras.doc.analyze.parse.model.ChapterModel;
import cn.com.cfae.iras.doc.analyze.parse.model.DocumentModel;
import cn.com.cfae.iras.doc.analyze.parse.model.ExtractBizModel;
import cn.com.cfae.iras.doc.analyze.parse.model.ExtractItem;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.xml.soap.Text;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.math.BigDecimal.ROUND_HALF_DOWN;
import static java.math.BigDecimal.ROUND_HALF_UP;

/**
 * Created by 佟媛媛 on 18/10/29.
 */
@Component("C1001")
@Scope("prototype")
public class C1001 extends BaseComponent {
    private static Logger logger = LoggerFactory.getLogger(C1001.class);

    @Autowired
    U1004 u1004;

    @Override
    public List<ComponentResult> handlerM() {
        logger.info("开始调用C1001组件，处理M表..............");
        String checkType = "M";
        List<ComponentResult> componentResults = ruleCheck(checkType);
        return componentResults;
    }

    @Override
    public List<ComponentResult> handlerBM() {
        logger.info("开始调用C1001组件，处理BM表..............");
        String checkType = "BM";
        List<ComponentResult> componentResults = ruleCheck(checkType);
        return componentResults;
    }

    @Override
    public List<ComponentResult> handlerDM() {
        logger.info("开始调用C1001组件，处理DM表..............");
        String checkType = "DM";
        List<ComponentResult> componentResults = ruleCheck(checkType);
        return componentResults;
    }

    @Override
    public List<ComponentResult> handlerBDM() {
        logger.info("开始调用C1001组件，处理BDM表..............");
        String checkType = "BDM";
        List<ComponentResult> componentResults = ruleCheck(checkType);
        return componentResults;
    }

    @Deprecated
    private ComponentResult dealData(Map<String, Map<String, ExtractItem>> map,String itemName,ChapterModel chapterModel){
        ComponentResult componentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),"是否可能涉及重大资产重组","",false,getRegulationId(),chapterModel.getStartPage(),null,"03");

        Set<String> years = map.keySet();

        Map<String,ExtractItem> extractItemMap = new HashMap<>();

        int num=0;

        for(String year:years){
            ExtractItem extractItem = map.get(year).get(itemName);
            if(extractItem!=null){
                KVText kvTextValue = extractItem.getValue();

                if(kvTextValue!=null){
                    if(StringUtils.isNotEmpty(kvTextValue.getText())){
                        extractItemMap.put(year,extractItem);
                    }else{
                        num++;
                    }
                }else{
                    num++;
                }
            }else{
                num++;
            }
        }

        if(num>0){
            componentResult.setExist("03");
            StringBuilder promptMessage = new StringBuilder();
            if(itemName.equals("ZCZJ")){
                promptMessage.append("资产总额");
            }else if(itemName.equals("SYZQY")){
                promptMessage.append("净资产");
            }else if(itemName.equals("YYSR")){
                promptMessage.append("营业收入");
            }
            componentResult.setAnnotationFlag(true);
            componentResult.setPromptMessage(promptMessage.append("数据缺失或未识别近三年及一期完整数据，无法计算变化幅度，建议人工核对").toString());
            return componentResult;
        }else{
            int maxYear = Integer.valueOf(Collections.max(years));
            int maxYearTemp = Integer.valueOf(Collections.max(years).substring(0,4));
            int minYear = Integer.valueOf(Collections.min(years));
            int minYearTemp = Integer.valueOf(Collections.min(years).substring(0,4));

            if(MapUtils.isNotEmpty(extractItemMap)){

                if(maxYearTemp-minYearTemp==3){
                    ExtractItem extractItem1 = extractItemMap.get(String.valueOf(maxYear)); //2018
                    ExtractItem extractItem2 = extractItemMap.get(String.valueOf(maxYearTemp-1).concat("12")); //2017
                    ExtractItem extractItem3 = extractItemMap.get(String.valueOf(maxYearTemp-2).concat("12")); //2016
                    ExtractItem extractItem4 = extractItemMap.get(String.valueOf(maxYearTemp-3).concat("12")); //2015

                    if(extractItem1.getValue()!=null){
                        TextLayout textLayout = extractItem1.getValue().getTextLayout();
                        List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
                        ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
                        textPosition.setX(textLayout.getLeft());
                        textPosition.setY(textLayout.getTop());
                        textPosition.setContent(textLayout.getText());
                        textPositionList.add(textPosition);
                        componentResult.setTextPosition(textPositionList);
                        componentResult.setPageNum(textLayout.getPageNumber());
                    }

                    String item = extractItem1.getKey().getText();

                    if(itemName.equals("ZCZJ") || itemName.equals("SYZQYHJ")){
                        Map<String,String> map1 = calculate(extractItem1.getValue().getText(),extractItem2.getValue().getText());//（18年季报-17年年报）/17年年报

                        logger.info("itemName：{}",itemName);
                        logger.info("年份1：{}，金额1：{}，年份2：{}，金额2：{}，变化幅度：{}%",maxYearTemp,extractItem1.getValue().getText(),maxYearTemp-1,extractItem2.getValue().getText(),map1.get("calculated"));

                        if(Integer.valueOf(map1.get("flag"))==-1){
                            Map<String,String> map2 = calculate(extractItem2.getValue().getText(),extractItem3.getValue().getText());//（17年季报-16年年报）/16年年报

                            logger.info("年份1：{}，金额1：{}，年份2：{}，金额2：{}，变化幅度：{}%",maxYearTemp-1,extractItem2.getValue().getText(),maxYearTemp-2,extractItem3.getValue().getText(),map2.get("calculated"));

                            if(Integer.valueOf(map2.get("flag"))==-1){
                                Map<String,String> map3 = calculate(extractItem3.getValue().getText(),extractItem4.getValue().getText());//（16年季报-15年年报）/15年年报

                                logger.info("年份1：{}，金额1：{}，年份2：{}，金额2：{}，变化幅度：{}%",maxYearTemp-2,extractItem3.getValue().getText(),maxYearTemp-3,extractItem4.getValue().getText(),map3.get("calculated"));

                                if(Integer.valueOf(map3.get("flag"))==-1){
                                    componentResult.setExist("01");
                                    componentResult.setPromptMessage(item.concat("变化幅度未超过50%"));
                                }else{
                                    componentResult.setExist("02");
                                    String promptMessage = String.valueOf(maxYearTemp-2).concat(item).concat("与").concat(String.valueOf(maxYearTemp-3)).concat(item).concat(" 计算后的变化幅度为：").concat(map3.get("calculated").concat("% ;"));
                                    componentResult.setPromptMessage(promptMessage);
                                    return componentResult;
                                }
                            }else{
                                componentResult.setExist("02");
                                String promptMessage = String.valueOf(maxYearTemp-1).concat(item).concat("与").concat(String.valueOf(maxYearTemp-2)).concat(item).concat(" 计算后的变化幅度为：").concat(map2.get("calculated").concat("% ;"));
                                componentResult.setPromptMessage(promptMessage);
                                return componentResult;
                            }
                        }else{
                            componentResult.setExist("02");
                            String promptMessage = String.valueOf(maxYearTemp).concat(item).concat("与").concat(String.valueOf(maxYearTemp-1)).concat(item).concat(" 计算后的变化幅度为：").concat(map1.get("calculated").concat("% ;"));
                            componentResult.setPromptMessage(promptMessage);
                            return componentResult;
                        }
                    }else if(itemName.equals("YYSR")){
                        Map<String,String> map1 = calculate(extractItem2.getValue().getText(),extractItem3.getValue().getText());//(17年-16年)/16年

                        logger.info("itemName：{}",itemName);
                        logger.info("年份1：{}，金额1：{}，年份2：{}，金额2：{}，变化幅度：{}%",maxYearTemp-1,extractItem2.getValue().getText(),maxYearTemp-2,extractItem3.getValue().getText(),map1.get("calculated"));

                        if(Integer.valueOf(map1.get("flag"))==-1){
                            Map<String,String> map2 = calculate(extractItem3.getValue().getText(),extractItem4.getValue().getText());//(16年-15年)/15年

                            logger.info("年份1：{}，金额1：{}，年份2：{}，金额2：{}，变化幅度：{}%",maxYearTemp-2,extractItem3.getValue().getText(),maxYearTemp-3,extractItem4.getValue().getText(),map2.get("calculated"));

                            if(Integer.valueOf(map2.get("flag"))==-1){
                                componentResult.setExist("01");
                                componentResult.setPromptMessage(item.concat("变化幅度未超过50%"));
                            }else{
                                componentResult.setExist("02");
                                String promptMessage = String.valueOf(maxYearTemp-2).concat(item).concat("与").concat(String.valueOf(maxYearTemp-3)).concat(item).concat(" 计算后的变化幅度为：").concat(map2.get("calculated").concat("%"));
                                componentResult.setPromptMessage(promptMessage);
                                return componentResult;
                            }
                        }else{
                            componentResult.setExist("02");
                            String promptMessage = String.valueOf(maxYearTemp-1).concat(item).concat("与").concat(String.valueOf(maxYearTemp-2)).concat(item).concat(" 计算后的变化幅度为：").concat(map1.get("calculated").concat("%"));
                            componentResult.setPromptMessage(promptMessage);
                            return componentResult;
                        }

                    }
                }else{
                    // 05 - 报表时间存在问题
                    componentResult.setExist("05");
                }

            }
        }

        return componentResult;
    }

    private Map<String,String> calculate(String str1,String str2){
        Map<String,String> map = new HashMap();

        BigDecimal num1 = new BigDecimal(str1);
        BigDecimal num2 = new BigDecimal(str2);

        BigDecimal num3 = num1.subtract(num2);
        BigDecimal num4 = num3.divide(num2,4,ROUND_HALF_UP);

        logger.info("计算的值为：{}",num4.stripTrailingZeros().toPlainString());

//        int num = num4.compareTo(new BigDecimal(0.5));

        int num = 0;

        int tempCompareNum = num4.compareTo(BigDecimal.ZERO);

        if(tempCompareNum==-1){
            BigDecimal num5 = num4.abs();
            num = num5.compareTo(new BigDecimal(0.5));
        }else{
            num = num4.compareTo(new BigDecimal(0.5));
        }

        BigDecimal calculated = num4.multiply(new BigDecimal(100));

        map.put("flag",String.valueOf(num));
        map.put("calculated",calculated.stripTrailingZeros().toPlainString());

        return map;
    }

    private String replaceComma(String text){
        return text.replaceAll("[,|，|\\s]{1,}","");
    }

    private Map<String,String> getDataFromTable(Map<String, Map<String, ExtractItem>> map,String itemName){
        Map<String,String> resultMap = new HashMap<>();

        Set<String> yearSet = map.keySet();

        for(String year:yearSet){
            Map<String, ExtractItem> extractItemMap = map.get(year);

            if(MapUtils.isNotEmpty(extractItemMap)){
                ExtractItem extractItem = extractItemMap.get(itemName);
                if(extractItem!=null){
                    KVText kvTextValue = extractItem.getValue();
                    if(kvTextValue!=null){
                        if(StringUtils.isNotEmpty(kvTextValue.getText())){
                            logger.info("itemName：{}，year：{}，text：{}",itemName,year,kvTextValue.getText());
                            resultMap.put(year.substring(0,4),replaceComma(kvTextValue.getText()));
                        }
                    }
                }
            }
        }

        return resultMap;
    }

    //验证表格年份是否完整
    private Boolean verifiedYear(Set<String> yearSet,String checkType){
        String maxYear = Collections.max(yearSet);
        String minYear = Collections.min(yearSet);

        int num = Integer.parseInt(maxYear) - Integer.parseInt(minYear);

        if(checkType.equals("M") || checkType.equals("BM")){
            if(num!=3){
                return false;
            }
        }else if(checkType.equals("DM") || checkType.equals("BDM")){
            if(num!=2){
                return false;
            }
        }
        return true;
    }

    //判断数据是否未披露
    private Boolean symbolicJudgment(String text){
        String regex = "(——|-|--|/){1,}";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);
        return matcher.matches();
    }

    private TextLayout getTextLayout(Map<String, Map<String, ExtractItem>> map,String itemName){
        TextLayout textLayout= null;

        Set<String> yearSet = map.keySet();

        for(String year:yearSet){
            Map<String, ExtractItem> extractItemMap = map.get(year);
            if(MapUtils.isNotEmpty(extractItemMap)) {
                ExtractItem extractItem = extractItemMap.get(itemName);
                if (extractItem != null) {
                    KVText kvTextKey = extractItem.getKey();
                    if(kvTextKey.getTextLayout()!=null){
                        return kvTextKey.getTextLayout();
                    }
                }
            }
        }
        return textLayout;
    }

    private Map<String,String> dataCompute(Map<String,String> dataMap,String itemName,String checkType){
        Map<String,String> itemNameMap = new HashMap<>();
        itemNameMap.put("ZCZJ","资产总额");
        itemNameMap.put("SYZQYHJ","净资产");
        itemNameMap.put("YYSR","营业收入");

        Map<String,String> result = new HashMap<>();

        Set<String> yearSet = dataMap.keySet();

        int maxYear = Integer.parseInt(Collections.max(yearSet));
        logger.info("itemName：{}，最大年份：{}",itemName,maxYear);

        StringBuilder promptMessage = new StringBuilder();

        //未识别
        int unidentification=0;
        //未披露
        int undisclosed=0;
        //是否涉及
        boolean involveFlag = false;
        //是否识别
        boolean identifyFlag = false;

        if(checkType.equals("M") || checkType.equals("BM")){
            int y=0;

            if(itemName.equals("ZCZJ") || itemName.equals("SYZQYHJ")){
                y=0;
            }else if(itemName.equals("YYSR")){
                y=1;
            }

            for(int i=y;i<3;i++){
                String year1 = String.valueOf(maxYear-i);
                String data1 = dataMap.get(year1);
                String year2 = String.valueOf(maxYear-i-1);
                String data2 = dataMap.get(year2);
                logger.info("获取数据：year1：{}，data1：{}，year2：{}，data2：{}",year1,data1,year2,data2);

                if(StringUtils.isNotEmpty(data1) && StringUtils.isNotEmpty(data2)){
                    if(!symbolicJudgment(data1) && !symbolicJudgment(data2)){
                        Map<String,String> map = calculate(data1,data2);
                        logger.info("比较标志：{}，变化幅度：{}",map.get("flag"),map.get("calculated"));
                        if(Integer.valueOf(map.get("flag"))==1){
                            String msg = "可能涉及重大资产重组，".concat(year1).concat("年与").concat(year2).concat("年").concat(itemNameMap.get(itemName)).concat("计算后的变化幅度为：").concat(map.get("calculated")).concat("%");
                            promptMessage.append(msg);
                            involveFlag = true;
                            break;
                        }
                    }else{
                        if(symbolicJudgment(data1) && !symbolicJudgment(data2)){
                            String msg = "未披露".concat(year1).concat("年").concat(itemNameMap.get(itemName)).concat("数据，无法计算").concat(year1).concat("年与").concat(year2).concat("年变化幅度；");
                            identifyFlag = true;
                            promptMessage.append(msg);
                        }else if(!symbolicJudgment(data1) && symbolicJudgment(data2)){
                            String msg = "未披露".concat(year2).concat("年").concat(itemNameMap.get(itemName)).concat("数据，无法计算").concat(year1).concat("年与").concat(year2).concat("年变化幅度；");
                            identifyFlag = true;
                            promptMessage.append(msg);
                        }else if(symbolicJudgment(data1) && symbolicJudgment(data2)){
                            String msg = "未披露".concat(year1).concat("年和").concat(year2).concat("年").concat(itemNameMap.get(itemName)).concat("数据，无法计算").concat(year1).concat("与").concat(year2).concat("变化幅度；");
                            identifyFlag = true;
                            promptMessage.append(msg);
                            undisclosed++;
                        }
                    }
                }else{
                    if(StringUtils.isNotEmpty(data1) && StringUtils.isEmpty(data2)){
                        String msg = "未识别".concat(year2).concat("年").concat(itemNameMap.get(itemName)).concat("数据，无法计算").concat(year1).concat("年与").concat(year2).concat("年变化幅度；");
                        identifyFlag = true;
                        promptMessage.append(msg);
                    }else if(StringUtils.isEmpty(data1) && StringUtils.isNotEmpty(data2)){
                        String msg = "未识别".concat(year1).concat("年").concat(itemNameMap.get(itemName)).concat("数据，无法计算").concat(year1).concat("年与").concat(year2).concat("年变化幅度；");
                        identifyFlag = true;
                        promptMessage.append(msg);
                    }else if(StringUtils.isEmpty(data1) && StringUtils.isEmpty(data2)){
                        String msg = "未识别".concat(year1).concat("年和").concat(year2).concat("年").concat(itemNameMap.get(itemName)).concat("数据，无法计算").concat(year1).concat("与").concat(year2).concat("变化幅度；");
                        identifyFlag = true;
                        promptMessage.append(msg);
                        unidentification++;
                    }
                }
            }

            if(itemName.equals("ZCZJ") || itemName.equals("SYZQYHJ")){
                if(unidentification==3){
                    promptMessage.append("未识别".concat(itemNameMap.get(itemName)).concat("数据，无法计算变化幅度，建议人工核对"));
                }else{
                    if(undisclosed==3){
                        promptMessage.append("未披露".concat(itemNameMap.get(itemName)).concat("数据，无法计算变化幅度，建议人工核对"));
                    }else{
                        if(!involveFlag){
                            if(!identifyFlag){
                                result.put("flag","01");
                            }else{
                                result.put("flag","02");
                                result.put("promptMessage",promptMessage.toString());
                            }
                        }else{
                            result.put("flag","03");
                            result.put("promptMessage",promptMessage.toString());
                        }
                    }
                }
            }else if(itemName.equals("YYSR")){
                if(unidentification==2){
                    promptMessage.append("未识别".concat(itemNameMap.get(itemName)).concat("数据，无法计算变化幅度，建议人工核对"));
                }else{
                    if(undisclosed==2){
                        promptMessage.append("未披露".concat(itemNameMap.get(itemName)).concat("数据，无法计算变化幅度，建议人工核对"));
                    }else{
                        if(!involveFlag){
                            if(!identifyFlag){
                                result.put("flag","01");
                            }else{
                                result.put("flag","02");
                                result.put("promptMessage",promptMessage.toString());
                            }
                        }else{
                            result.put("flag","03");
                            result.put("promptMessage",promptMessage.toString());
                        }
                    }
                }
            }
        }

        return result;
    }

    public List<ComponentResult> ruleCheck(String checkType){
        DocumentModel documentModel = super.getExtractData();

        List<ComponentResult> componentResults = new ArrayList<>();

        ChapterModel chapterModel = documentModel.getChapterModel(getCatalogId());

        try{
            ComponentResult checkResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),"是否可能涉及重大资产重组","",false,getRegulationId(),3,null,"03");

            if(chapterModel!=null){
                checkResult.setPageNum(chapterModel.getStartPage());

                Map<String, Map<String, ExtractItem>> zcfzMap = chapterModel.getModel("ZCFZ").getTables();
                Map<String, Map<String, ExtractItem>> lrMap = chapterModel.getModel("LR").getTables();

                //资产总额
                ComponentResult zczjComponentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),"是否可能涉及重大资产重组","",true,getRegulationId(),chapterModel.getStartPage(),null,"03");
                //净资产(实际取值:所有者权益合计)
                ComponentResult jzcComponentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),"是否可能涉及重大资产重组","",true,getRegulationId(),chapterModel.getStartPage(),null,"03");
                //营业收入
                ComponentResult yysrComponentResult =  u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),"是否可能涉及重大资产重组","",true,getRegulationId(),chapterModel.getStartPage(),null,"03");

                //不涉及
                int uninvolvedCount = 0;
                //涉及
                int involvedCount = 0;

                //资产总额，净资产
                if(MapUtils.isNotEmpty(zcfzMap)){
                    Map<String,String> zczjDataMap = getDataFromTable(zcfzMap,"ZCZJ");

                    TextLayout textLayout = getTextLayout(zcfzMap,"ZCZJ");
                    if(textLayout!=null){
                        List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
                        ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
                        textPosition.setX(textLayout.getLeft());
                        textPosition.setY(textLayout.getTop());
                        textPosition.setContent(textLayout.getText());
                        textPositionList.add(textPosition);
                        zczjComponentResult.setTextPosition(textPositionList);
                        zczjComponentResult.setPageNum(textLayout.getPageNumber());
                    }

                    if(MapUtils.isNotEmpty(zczjDataMap)){
                        Set<String> zczjYearSet=zczjDataMap.keySet();

                        logger.info("verifiedYear：{}",verifiedYear(zczjYearSet,checkType));
                        if(verifiedYear(zczjYearSet,checkType)){

                            Map<String,String> map = dataCompute(zczjDataMap,"ZCZJ",checkType);
                            logger.info("flag：{}，promptMessage：{}",map.get("flag"),map.get("promptMessage"));

                            if(map.get("flag").equals("01")){
                                uninvolvedCount++;
                                zczjComponentResult.setPromptMessage("资产总额变化幅度未超过50%");
                            }else{
                                if(map.get("flag").equals("03")){
                                    involvedCount++;
                                }
                                zczjComponentResult.setPromptMessage(map.get("promptMessage"));
                            }

                        }else{
                            zczjComponentResult.setPromptMessage("合并资产负债表年份存在问题，无法计算资产总额变化幅度，建议人工核对");
                        }
                    }else{
                        zczjComponentResult.setPromptMessage("未识别资产总额数据，建议人工核对");
                    }

                    Map<String,String> jzcDataMap = getDataFromTable(zcfzMap,"SYZQYHJ");

                    TextLayout textLayout2 = getTextLayout(zcfzMap,"SYZQYHJ");
                    if(textLayout2!=null){
                        List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
                        ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
                        textPosition.setX(textLayout2.getLeft());
                        textPosition.setY(textLayout2.getTop());
                        textPosition.setContent(textLayout2.getText());
                        textPositionList.add(textPosition);
                        jzcComponentResult.setPageNum(textLayout2.getPageNumber());
                        jzcComponentResult.setTextPosition(textPositionList);
                    }

                    if(MapUtils.isNotEmpty(jzcDataMap)){
                        Set<String> jzcYearSet=jzcDataMap.keySet();

                        logger.info("verifiedYear：{}",verifiedYear(jzcYearSet,checkType));
                        if(verifiedYear(jzcYearSet,checkType)){
                            Map<String,String> map = dataCompute(jzcDataMap,"SYZQYHJ",checkType);
                            logger.info("flag：{}，promptMessage：{}",map.get("flag"),map.get("promptMessage"));

                            if(map.get("flag").equals("01")){
                                uninvolvedCount++;
                                jzcComponentResult.setPromptMessage("净资产变化幅度未超过50%");
                            }else{
                                if(map.get("flag").equals("03")){
                                    involvedCount++;
                                }
                                jzcComponentResult.setPromptMessage(map.get("promptMessage"));
                            }

                        }else{
                            jzcComponentResult.setPromptMessage("合并资产负债表年份存在问题，无法计算净资产变化幅度");
                        }
                    }else{
                        jzcComponentResult.setPromptMessage("未识别净资产数据，无法计算净资产变化幅度");
                    }

                }else{
                    zczjComponentResult.setPromptMessage("未识别合并资产负债表数据，无法计算资产总额变化幅度");
                    jzcComponentResult.setPromptMessage("未识别合并资产负债表数据，无法计算净资产变化幅度");
                }

                //营业收入
                if(MapUtils.isNotEmpty(lrMap)){
                    Map<String,String> yysrDataMap = getDataFromTable(lrMap,"YYSR");

                    TextLayout textLayout = getTextLayout(lrMap,"YYSR");
                    if(textLayout!=null){
                        List<ComponentResult.TextPosition> textPositionList = new ArrayList<>();
                        ComponentResult.TextPosition textPosition = new ComponentResult().new TextPosition();
                        textPosition.setX(textLayout.getLeft());
                        textPosition.setY(textLayout.getTop());
                        textPosition.setContent(textLayout.getText());
                        textPositionList.add(textPosition);
                        yysrComponentResult.setPageNum(textLayout.getPageNumber());
                        yysrComponentResult.setTextPosition(textPositionList);
                    }

                    if(MapUtils.isNotEmpty(yysrDataMap)){
                        Set<String> yysrYearSet=yysrDataMap.keySet();

                        logger.info("verifiedYear：{}",verifiedYear(yysrYearSet,checkType));
                        if(verifiedYear(yysrYearSet,checkType)){
                            Map<String,String> map = dataCompute(yysrDataMap,"YYSR",checkType);
                            logger.info("flag：{}，promptMessage：{}",map.get("flag"),map.get("promptMessage"));

                            if(map.get("flag").equals("01")){
                                uninvolvedCount++;
                                yysrComponentResult.setPromptMessage("营业收入变化幅度未超过50%");
                            }else{
                                if(map.get("flag").equals("03")){
                                    involvedCount++;
                                }
                                yysrComponentResult.setPromptMessage(map.get("promptMessage"));
                            }
                        }else{
                            yysrComponentResult.setPromptMessage("合并利润表年份存在问题，无法计算营业收入变化幅度");
                        }
                    }else{
                        yysrComponentResult.setPromptMessage("未识别营业收入数据，无法计算营业收入变化幅度");
                    }
                }else{
                    yysrComponentResult.setPromptMessage("未识别合并利润表数据，无法计算营业收入变化幅度");
                }

                if(uninvolvedCount==3){
                    ComponentResult componentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),"是否可能涉及重大资产重组","",false,getRegulationId(),chapterModel.getStartPage(),null,"03");
                    componentResult.setPromptMessage("不涉及重大资产重组");
                    componentResults.add(componentResult);
                    return componentResults;
                }else{
                    if(involvedCount>0){
                        zczjComponentResult.setExist("02");
                        jzcComponentResult.setExist("02");
                        yysrComponentResult.setExist("02");
                    }else{
                        zczjComponentResult.setExist("03");
                        jzcComponentResult.setExist("03");
                        yysrComponentResult.setExist("03");
                    }

                    componentResults.add(zczjComponentResult);
                    componentResults.add(jzcComponentResult);
                    componentResults.add(yysrComponentResult);
                    return componentResults;
                }
            }else{
                ComponentResult componentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),"是否可能涉及重大资产重组","",true,getRegulationId(),0,null,"03");
                componentResult.setPromptMessage("未识别合并资产负债表以及合并利润表数据");
                componentResults.add(componentResult);
                return componentResults;
            }
        }catch (Exception e){
            logger.error(e.getMessage(),e);
            if(componentResults.size()==0){
                ComponentResult componentResult = u1004.getComponentResult(getCatalogId(),getChapterId(),getRuleTitle(),"是否可能涉及重大资产重组","",true,getRegulationId(),1,null,"03");
                componentResult.setPromptMessage("未识别合并资产负债表以及合并利润表数据");
                if(chapterModel!=null) componentResult.setPageNum(chapterModel.getStartPage());
                componentResults.add(componentResult);
            }
        }
        return componentResults;
    }
}
